package org.gp.demo.timer.task;

import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

import org.gp.demo.timer.timerfactory.DemoTimer;

public class ListenerTask extends TimerTask {
	private static Map<DemoTimer, Date> task = new HashMap<DemoTimer, Date>();

	public static void initTask(DemoTimer timer, Date timerStartDate) {
		if (task.containsKey(timer)) {
			task.remove(timer);
		}
		task.put(timer, timerStartDate);
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		Iterator<DemoTimer> iter = task.keySet().iterator();
		while (iter.hasNext()) {
			DemoTimer timer = iter.next();
			Date startDate = task.get(timer);
			long poor = new Date().getTime() - startDate.getTime();
			if (poor == 120000 && timer.status == 0) {
				System.out.println("Timer Stop:" + timer.name);
				timer.cancel();
				// task.remove(timer);
			}
		}
	}

}
